package edu.towson.cosc490.incaseofemergency;

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class WeatherMap extends Activity {

	private WebView webView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_weather_map);
	    webView = (WebView) findViewById(R.id.webView);
	    openBrowser();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.weather_map, menu);
		return true;
	}
	private void openBrowser() {
		LocationManager locationManager =
		        (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
		Location myLoc = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
		String urlText = "http://www.wunderground.com/cgi-bin/findweather/getForecast?brand=wxmap&query=" + myLoc.getLatitude() + "," + myLoc.getLongitude();
		webView.getSettings().setDefaultZoom(WebSettings.ZoomDensity.FAR);
		webView.getSettings().setJavaScriptEnabled(true);
		webView.loadUrl(urlText);
	   }
}
